package com.demo.datastructure.linkedList;

/**
 * @description: 哨兵
 * @author: ljr
 * @time: 2021/4/14 17:41
 */
public class LinkedListSentinelDemo5 {

    public int find(char[] chars, int n, char key){
        if(chars == null || n == 0){ return -1;}
        if(chars[n-1]  == key){
            return n-1;
        }
        chars[n-1] = key;

        int num = 0;
        while(chars[num] != key){
            num++;
        }
        if(num == n-1){ return -1;}
        return num;
    }

}



